<template>
  <div id="patients">
    <div class="search">
       <el-select v-model="sou.cha" placeholder="请选择身份">
      <el-option label="教职工" value="teacher"></el-option>
      <el-option label="学生" value="student"></el-option>
    </el-select>
     <el-input v-model="sou.No" placeholder="请输入病历卡"></el-input>
        <el-button size="mini" type="success" @click="search()" style="margin-right:10px">查询</el-button>
         <el-button size="mini" type="success"  @click="refresh()">重置</el-button>
    </div>
    <div class = "teacher">
        <el-table :data="formData.data" style="width: 100%">
      <el-table-column align="center" label="姓名">
        <template slot-scope="scope">
          <i class="el-icon-user"></i>
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="卡号" >
        <template slot-scope="scope">
          <span>{{ scope.row.personNo }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="出生日期">
        <template slot-scope="scope">
          <i class="el-icon-user"></i>
          <span>{{timez(scope.row.birthDate) }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="电话">
        <template slot-scope="scope">
      
          <span>{{ scope.row.telephone }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="地址">
        <template slot-scope="scope">
      
          <span>{{ scope.row.contactAddress }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="身份">
        <template >
          <span style="color:#85CE61">教职工</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="200px">
        <template>
          <span>暂无权限</span>
        </template>
      </el-table-column>
    </el-table>
     <!-- 分页 -->
    <div class="pagination" style="margin-bottom:30px">
      <el-pagination layout="prev, pager, next" :total="pages" :page-size="pageSize"  @current-change="handleCurrentChange"></el-pagination>
    </div>

    </div>

    <div class = "student" >
        <el-table :data="stuData.data" style="width: 100%;" >
      <el-table-column align="center" label="姓名">
        <template slot-scope="scope">
          <i class="el-icon-user"></i>
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="出生日期">
        <template slot-scope="scope">
          <i class="el-icon-user"></i>
          <span>{{timez(scope.row.birthDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="卡号" >
        <template slot-scope="scope">
          <span>{{ scope.row.personNo }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="电话">
        <template slot-scope="scope">
      
          <span>{{ scope.row.telephone }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="地址">
        <template slot-scope="scope">
      
          <span>{{ scope.row.contactAddress }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="身份">
        <template >
          <span style="color:#85CE61">学生</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作" width="200px">
        <template>
          <span>暂无权限</span>
        </template>
      </el-table-column>
    </el-table>
     <!-- 分页 -->
      <div class="pagination">
      <el-pagination layout="prev, pager, next" :total="pages2" :page-size="pageSize"  @current-change="handleCurrentChange1"></el-pagination>
    </div>
    </div>
   
    <!-- <ADD @close="closeshow" :fromdata="from" :theID="theID" :kind="kind" :dialogFormVisible="isshow"></ADD> -->
  </div>
</template>
<script>
import{mapActions,mapMutations,mapGetters}from'vuex'
import {time}from'@/utils/time'
export default {
  name:'ourPatients',
  data(){
    return{
      formData:[],
      stuData:[],
      //搜索用
     sou:{
       cha:'',
       No:''
     },
      nowpage:1,
      pageSize:3,
      currentpage:1
    }
  },
  created(){
    this.getFormData(1)
    this.getStuData(1)
  },
  methods:{
     ...mapActions(['tongyong']),
     //时间
      timez(obj){
      return time(obj)
    },
       //获取当前页
    handleCurrentChange(val){
        this.nowpage = val
        console.log(this.nowpage)
        this.getFormData(this.nowpage)
        }, 
         handleCurrentChange1(val){
           console.log(val)
        this.currentpage = val
        console.log(this.currentpage)
        this.getStuData(this.currentpage)
        }, 
        //获取教职工数据
      getFormData(nowpage){
      let page = nowpage
      let pageSize = this.pageSize
      let status = '01'
      this['tongyong']({
        name:'GET_STATUS',
        data:{page,pageSize,status}
      }).then(resp=>{
     
      this.formData = resp.data
     console.log(this.formData.data.length)
      })
    },
    //获取学生数据
    getStuData(nowpage){
       let page = nowpage
      let pageSize = this.pageSize
      let status = '02'
      this['tongyong']({
        name:'GET_STATUS',
        data:{page,pageSize,status}
      }).then(resp=>{
     
      this.stuData = resp.data
       console.log(this.stuData.data.length)
      })
    },
    search(){
      if(this.sou.cha=='teacher'){
        let page = 1
        let pageSize = String(this.pageSize)
        let no = this.sou.No
        console.log('teacher')
       let data = {
         page,
         pageSize,
         no
       }
         this['tongyong']({
        name:'CHA_PATIENTSBYNO',
        data:data
      }).then(resp=>{
     console.log(resp)
      this.formData = resp.data
      this.sou ={}
      })
      }else if(this.sou.cha=='student'){
          console.log('student')
        let page = 1
        let pageSize = String(this.pageSize)
        let no = this.sou.No
        console.log('teacher')
         this['tongyong']({
        name:'CHA_PATIENTSBYNO',
        data:{page,pageSize,no}
      }).then(resp=>{
        console.log(resp.data)
      this.stuData = resp.data
    this.sou ={}
      })
      }else{
        this.$message('请选择身份')
      }
     
    },
     refresh(){
      console.log('9999')
     this.getFormData(1)
    this.getStuData(1)
    },
    add(){

    }
  },
   computed:{
    pages(){
      // if(this.formData.data.length<3){
      // let length = this.formData.data.length
      // console.log(this.formData.data.length)
      // return length
      // }else{
      //   return this.formData.count
      // }
       return this.formData.count
     
    },
    pages2(){
      //  if(this.stuData.data.length<3){
      //    let length = this.stuData.data.length
      // console.log(this.stuData.data.length)
      // return length
      // }else{
      //   return this.stuData.count
      // }
       return this.stuData.count
    }
   }
  
};
</script>
<style lang="less" scoped>
.search{
  display: flex;
  justify-content: center;
  margin-bottom:10px;
  .el-input{
    width:200px;
  }
}
.el-button+.el-button{
  margin: 0;
}
</style>
